package com.youlemall.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.youlemall.common.pojo.PageResult;
import com.youlemall.pojo.TypeTemplate;
import com.youlemall.service.TypeTemplateService;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 2 * @Author: kevin
 * 3 * @Date: 2019/7/15 16:30
 * 4
 */

@RestController
@RequestMapping("/typeTemplate")
public class TypeTemplateController {

	@Reference(retries = 10000)
	private TypeTemplateService templateService;

	@GetMapping("/findByPage")
	public PageResult findByPage(TypeTemplate typeTemplate, Integer page,
								 @RequestParam(defaultValue = "10") Integer rows){
	return templateService.findByPage(typeTemplate,page,rows);
	}


	@PostMapping("/save")
	public Boolean saveTypeTemplate(@RequestBody TypeTemplate typeTemplate){
		try {
			templateService.save(typeTemplate);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@PostMapping("/update")
	public Boolean updateTypeTemplate(@RequestBody TypeTemplate typeTemplate){
		try {
			templateService.update(typeTemplate);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@GetMapping("/delete")
	public Boolean delete(Long[] ids){
		try {
			templateService.deleteAll(ids);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@GetMapping("/findtypeTemplate")
	public List<Map<String,Object>> findtypeTemplate(){
		try {
			return templateService.findtypeTemplate();
		} catch (Exception e) {
			throw  new RuntimeException(e);
		}
	}

}
